package br.pucrs.lognplay.repository.mapper.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import br.pucrs.lognplay.entity.LogSource;
import br.pucrs.lognplay.repository.LogSourceRepository;
import br.pucrs.lognplay.repository.RepositoryException;

public class LogSourceMapper extends GenericMapper<LogSource, String> implements LogSourceRepository {

	public LogSourceMapper() {
		super();
	}

	public LogSourceMapper(EntityManager entityManager) {
		super(entityManager);
	}

	public List<LogSource> listByClientId(String clientId) throws RepositoryException {
		try {
			TypedQuery<LogSource> typedQuery = getEntityManager().createQuery("SELECT logSource FROM LogSource logSource WHERE logSource.client.id = :clientId", LogSource.class);
			typedQuery.setParameter("clientId", clientId);
			return typedQuery.getResultList();
		} catch (Exception e) {
			throw new RepositoryException("Error on list log sources by client id", e);
		}
	}
}
